﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Reflection;

namespace AnaViewer
{
    /// <summary>
    /// “关于本程序”对话框。
    /// </summary>
    internal partial class AboutForm : Form
    {

        /// <summary>
        /// 常量类。
        /// </summary>
        private class Consts
        {
            internal const string CompanyLink = "http://chuangen.name/";
        }

        private bool m_showing = true;

        /// <summary>
        /// 初始化类 <see cref="AboutForm"/> 的新实例。
        /// </summary>
        internal AboutForm()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 引发 <see cref="E:System.Windows.Forms.Form.Load"></see> 事件。
        /// </summary>
        /// <param name="e">包含事件数据的 <see cref="T:System.EventArgs"></see>。</param>
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            this.Text = String.Format("关于 {0}", Application.ProductName);
            this.labelProductName.Text = String.Format("{0}", Application.ProductName);
            this.labelProductVersion.Text = String.Format("{0}", Application.ProductVersion);
            AssemblyName[] other = Assembly.GetExecutingAssembly().GetReferencedAssemblies();

            //foreach (AssemblyName a in other)
            //{
            //    listAssemblies.Items.Add(string.Format("{0} ({1})", a.Name, a.Version));
            //}

            this.Opacity = 0.0;
            this.Activate();
            this.Refresh();
            fadeTimer.Start();
        }

        private void linkCompany_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {//访问网站
            try
            {
                System.Diagnostics.Process.Start(Consts.CompanyLink);
            }
            catch
            {
                //无法打开网站。
            }
        }

        private void butOK_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void fadeTimer_Tick(object sender, EventArgs e)
        {
            if (m_showing)
            {
                double d = 1000.0 / fadeTimer.Interval / 100.0;
                if (Opacity + d >= 1.0)
                {
                    Opacity = 1.0;
                    fadeTimer.Stop();
                }
                else
                {
                    Opacity = Opacity + d;
                }
            }
            else
            {
                double d = 1000.0 / fadeTimer.Interval / 100.0;
                if (Opacity - d <= 0.0)
                {
                    Opacity = 0.0;
                    fadeTimer.Stop();
                }
                else
                {
                    Opacity = Opacity - d;
                }
            }
        }

        private void AboutForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            if(this.Owner!=null)
                Owner.Activate();
            m_showing = false;
            fadeTimer.Start();
        }
    }
}